package br.com.registrofinancas.view;

import java.text.SimpleDateFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import br.com.registrofinancas.R;
import br.com.registrofinancas.database.MovimentosEntradaDAO;
import br.com.registrofinancas.database.MovimentosSaidaDAO;
import br.com.registrofinancas.model.NotificationVO;
import br.com.registrofinancas.util.CurrencyUtils;

public class NotificacaoConfirmaMovimentoActivity extends Activity{
	private TextView etTipo;
	private TextView etValor;
	private TextView etData;
	private TextView etCategoria;
	private TextView etObservacao;
	private Button btConfirma;
	private Button btCancela;
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_confirma_movimento_notification);
		etTipo = (TextView) findViewById(R.id.activity_confirma_movimento_notification_tipo);
		etValor = (TextView) findViewById(R.id.activity_confirma_movimento_notification_valor);
		etData = (TextView) findViewById(R.id.activity_confirma_movimento_notification_data);
		etCategoria = (TextView) findViewById(R.id.activity_confirma_movimento_notification_categoria);
		etObservacao = (TextView) findViewById(R.id.activity_confirma_movimento_notification_observacao);
		
		
		final Bundle extras = getIntent().getExtras();
		final NotificationVO notificacaoVO = (NotificationVO) extras.getSerializable("notificacaoVO");
		switch (notificacaoVO.getTipo()) {
		case INCOME:
			etTipo.setText("Entrada");
			etTipo.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_blue_dark));
			etValor.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_blue_dark));
			etData.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_blue_dark));
			etCategoria.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_blue_dark));
			etObservacao.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_blue_dark));
			break;
		case OUTCOME:
			etTipo.setText("Saida");
			etTipo.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_red_dark));
			etValor.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_red_dark));
			etData.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_red_dark));
			etCategoria.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_red_dark));
			etObservacao.setTextColor(getApplicationContext().getResources().getColor(android.R.color.holo_red_dark));			
			break;
		default:			
			break;
		}
		
		etValor.setText(CurrencyUtils.formataValor(notificacaoVO.getValor(), this));
		SimpleDateFormat formataData = new SimpleDateFormat("dd/MM/yyyy");
		etData.setText(formataData.format(notificacaoVO.getData()));
		etCategoria.setText(notificacaoVO.getCategoria());
		etObservacao.setText(notificacaoVO.getObservacao());
		
		btCancela = (Button) findViewById(R.id.activity_confirma_movimento_notification_cancela);
		btCancela.setOnClickListener(new View.OnClickListener() {	
			@Override
			public void onClick(View view) {
				switch (notificacaoVO.getTipo()) {
				case INCOME:
					MovimentosEntradaDAO entradaDAO= new MovimentosEntradaDAO(NotificacaoConfirmaMovimentoActivity.this);
					entradaDAO.delete(entradaDAO.getEntradaPorId(notificacaoVO.getIdMovimento()));
					break;
				case OUTCOME:
					MovimentosSaidaDAO saidaDAO= new MovimentosSaidaDAO(NotificacaoConfirmaMovimentoActivity.this);
					saidaDAO.delete(saidaDAO.getSaidaPorId(notificacaoVO.getIdMovimento()));
					break;
				default:			
					break;
				}		
				finish();
			}
		});
		
		btConfirma = (Button) findViewById(R.id.activity_confirma_movimento_notification_confirma);
		btConfirma.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				finish();
			}
		});
	}
}
